/*
 * ButtonWidget.fx
 *
 * Created on 11-Feb-2009, 19:25:22
 */

package widgets;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Text;
import javafx.scene.text.Font;


/**
 * @author beol
 */

public class ButtonWidget extends CustomNode {

    public var x: Number;
    public var y: Number;

    public var text = "42";
    public var offsetX: Number = 5;
    public var offsetY: Number = 5;

    public var height: Number = 30;
    public var width: Number = 180;

    public var isPressed: Boolean = false;

    var node: Group = Group {

    }

    var background: Rectangle = Rectangle {
        translateX: x,
        translateY: y
        width: width,
        height: height
        fill: Color.LIGHTGRAY
        stroke: Color.WHITE
        strokeWidth: 2
        arcHeight: 20
        arcWidth: 20

        onMousePressed: function( e: MouseEvent ):Void {
            background.stroke = Color.BLACK;
        }

        onMouseReleased: function( e: MouseEvent ):Void {
            background.stroke = Color.WHITE;
        }

        onMouseEntered: function( e: MouseEvent ):Void {
            background.fill = Color.WHITE;

        }

        onMouseExited: function( e: MouseEvent ):Void {
            background.fill = Color.LIGHTGRAY;
        }

        onMouseClicked: function( e: MouseEvent ):Void {
            isPressed = true;
        }
        
    }

    var phrase: Text = Text {
        translateX: x + offsetX
        translateY: y + offsetY
        font: Font {
            size: 16
        }
        content: text
    }

    protected override function create(): Node {
        node.content = [background, phrase];
        return node;
    }
}
